package com.shiliao.app.activity.interlocution.ui;


import android.content.Intent;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v4.widget.SwipeRefreshLayout;

import com.shiliao.app.R;
import com.shiliao.app.manager.YMUserManager;
import com.shiliao.app.utils.MyWebView;
import com.shiliao.app.utils.WebSetUtil;
import com.shiliao.app.utils.YMServerUtil;
import com.shiliao.app.weight.ProgressWebView;
import com.yimei.framework.base.ui.BaseFragment;

import butterknife.BindView;

/**
 * Created by yinzhiqiang on 2017/9/11.
 */

public class CommonProblemFragment extends BaseFragment {

    @BindView(R.id.webview)
    ProgressWebView webview;

    @BindView(R.id.swip_refresh)
    SwipeRefreshLayout refresh;
    private MyWebView mWebView;

    @Override
    public int getLayoutId() {
        return R.layout.activity_daily_knowledge;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void initFragmentView() {
        super.initFragmentView();
        WebSetUtil.setWebView(webview);
        initData();
        final String url = YMServerUtil.getServerUrl() + YMServerUtil.ACTION_COMMON_PROBLEM + "?user_id=" + YMUserManager.getUserId(getContext());
        refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                webview.loadUrl(url);
            }
        });

        webview.loadUrl(url);

    }

    private void initData() {
        Intent intent = new Intent(getContext(), CommonProblemDetailActivity.class);
        String request_url = YMServerUtil.COMMON_PROBLEM_REFERASHURL;
        request_url = request_url + "?user_id=" + YMUserManager.getUserId(getContext());
        mWebView = new MyWebView(webview, getContext(), YMServerUtil.COMMON_PROBLEM_COTURL, intent,
                refresh, request_url);
        webview.setWebViewClient(mWebView);
    }


}
